//
// Created by yewa on 2021/11/11.
//
#include <jni.h>
#include <iostream>
#include <DrawBackground.h>

DrawBackground *drawBackground;

extern "C" JNIEXPORT jstring JNICALL
Java_com_bytecodezz_app_learn1_NativeRender_stringFromJNI(
        JNIEnv *env,
        jclass clazz) {
    std::string hello = "Hello NativeImpl from C++";

    return env->NewStringUTF(hello.c_str());
}


extern "C" JNIEXPORT void JNICALL
Java_com_bytecodezz_app_learn1_NativeRender_native_1Init(JNIEnv *env, jobject instance) {
//    if (drawBackground == NULL) {
        drawBackground = new DrawBackground();
//    }
    drawBackground->init();
}


extern "C" JNIEXPORT void JNICALL
Java_com_bytecodezz_app_learn1_NativeRender_native_1SurfaceChanged(JNIEnv *env, jobject instance,
                                                                   jint width,
                                                                   jint height) {
    drawBackground->onSurfaceChanged(width, height);
}

extern "C" JNIEXPORT void JNICALL
Java_com_bytecodezz_app_learn1_NativeRender_native_1Draw(JNIEnv *env, jobject instance) {
    drawBackground->draw();
}